home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / Context Check Modules / Standard CC Modules / File Context / File.c next >
Encoding:
C/C++ Source or Header  |  1994-05-03  |  10.9 KB  |  361 lines  |  [TEXT/MPS ]

  1. //    Copyright:    © 1993 Apple Computer, Inc. All rights reserved.
  2. //                Victor J. Hnyp
  3. //    Date:        11-Mar-93
  4.  
  5. // Revisions
  6. //
  7. //    05/01/94    JAJ    2.09    Fixed:    Stubbed all functiosn which used hard coded strings
  8. //                                    for file names (isPrintMonitor, isAppleShare, isEtherTalk, & isTokenTAlk)
  9. //                                    they were left in place for compatibility
  10. //
  11. //    03/11/93    VJH    2.08    Fixed:    Removed EtherTalk Prep as required file for isEtherTalk
  12. //
  13. //    02/24/93    VJH    2.07    Fixed:    Removed isSharedOwned context check
  14. //
  15. //    02/20/93    GB    2.06    Fixed:    Setup ioNamePtr before calling PBHGetVInfo
  16. //
  17. //    02/08/93    VJH    2.05    Fixed:    isControlPanel, isFileExists
  18. //
  19. //    01/18/93    VJH    2.04    Added:    isFileExists
  20. //
  21. //    01/14/93    VJH    2.03            General RENO build update
  22. //
  23. //    12/21/92    VJH    2.02    Fixed:    Typecast of PBGetCatInfo((CInfoPBPtr)&thePB) for stricter compile checking
  24. //
  25. //    11/29/92    VJH    2.01    Added:    Is the frontmost (active) window the same name as the startup volume name?
  26. //                                    Is the name of any open and visible window the same name as the startup volume name?
  27. //                                    Is the current directory the startup disk's?
  28. //                                    Is PrintMonitor installed?
  29. //                                    Is AppleShare support software installed?
  30. //                                    Is EtherTalk support software installed?
  31. //                                    Is TokenTalk support software installed?
  32. //                                    Is the Control Panel named "..." installed?
  33. //                                    Is the shared folder whose path is "..." owned by the user?
  34. //
  35.  
  36. #pragma    load "AllHeaders.dump"
  37.  
  38. #include "Utility.h"
  39. #include "Proto.h"
  40. #include "Context.h"
  41. #include "File.h"
  42.  
  43.  
  44. /* ------------------ Forward Declarations --------------------- */
  45. pascal Boolean     IsFrontWindowStartupVol();
  46. pascal Boolean     IsOpenWindowStartupVol();
  47. pascal Boolean     IsCDOnStartupVol();
  48. pascal Boolean     IsPrintMonitorInstalled();
  49. pascal Boolean     IsAppleShareInstalled();
  50. pascal Boolean     IsEtherTalkInstalled();
  51. pascal Boolean     IsTokenTalkInstalled();
  52. pascal Boolean    IsCPInstalled(FileStatePtr fileMsg);
  53. pascal Boolean    IsFileInstalled(FileStatePtr fileMsg);
  54. OSErr    FindSysFolder(short *foundVRefNum, long *foundDirID);
  55. OSErr    FindExtFolder(short *foundVRefNum, long *foundDirID);
  56. OSErr    FindFile(char *filename, short theVolume, long theDirID);
  57. short    GetSFCurVol();
  58.  
  59. pascal OSErr main(ContextSelectorPtr msg, Size inSize,
  60.                     void* outMessage, Size* outSize, Handle /*startGlobals*/)
  61. {
  62.     Boolean        ret    =    false;
  63.     OSErr        err    =    errAECorruptData;
  64.     
  65.     if(inSize < sizeof(ContextSelector))                    /* If inSize is < length of selector (a long), */
  66.         return(err);                                        /* return an error. Would be nice to have a specific error # */
  67.     
  68.     switch (msg->selector)
  69.     {
  70.         case isFrontStartup:                // Is the frontmost (active) window the same name as the startup volume name?
  71.             ret = IsFrontWindowStartupVol();
  72.             break;
  73.  
  74.         case isOpenStartup:                    // Is the name of any open and visible window the same name as the startup volume name?
  75.             ret = IsOpenWindowStartupVol();
  76.             break;
  77.  
  78.         case isCDStartup:                    // Is the current directory the startup disk's?
  79.             ret = IsCDOnStartupVol();
  80.             break;
  81.  
  82.         case isPrintMonitor:                // Is PrintMonitor installed?    
  83.             break;                            //    Always return false <JJ>
  84.  
  85.         case isAppleShare:                    // Is AppleShare support software installed?
  86.             break;                            //    Always return false <JJ>
  87.  
  88.         case isEtherTalk:                    // Is EtherTalk support software installed?
  89.             break;                            //    Always return false <JJ>
  90.  
  91.         case isTokenTalk:                    // Is TokenTalk support software installed?
  92.             break;                            //    Always return false <JJ>
  93.  
  94.         case isControlPanel:                // Is the Control Panel named "..." installed?
  95.             ret = IsCPInstalled((FileStatePtr)msg);
  96.             break;
  97.  
  98.         case isFileExists:                    // Is the File named "..." within the system-defined folder ...? 
  99.             ret = IsFileInstalled((FileStatePtr)msg);
  100.             break;
  101.  
  102.         default:                                            /* None of the pre-defined types. Exit with error */
  103.             return(err);                                    /* Would be nice to have a specific error # */
  104.             break;
  105.     }
  106.  
  107.     err    = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
  108.     return(err);
  109. }
  110.  
  111.  
  112. pascal Boolean     IsFrontWindowStartupVol()
  113. {
  114.     Boolean        ret    =    false;
  115.     short        startupVolRefNum;
  116.     long        systemDirID;
  117.     VolumeParam    thePB;
  118.     WindowPtr    wPtr;
  119.     OSErr        localError;
  120.     Str255        winTitle;
  121.     char        nameString[32];
  122.     
  123.     if( FindSysFolder( &startupVolRefNum, &systemDirID ))    // Error getting volume ref num of startup volume
  124.         return( ret );
  125.  
  126.     /* Set the param block up for getting information about the startup volume */
  127.     thePB.ioCompletion = nil;
  128.     thePB.ioVolIndex = 0;                                    // Use ioVRefNum field only
  129.     thePB.ioVRefNum = startupVolRefNum;                        // Use the startup volume reference for lookup
  130.     thePB.ioNamePtr = nameString;
  131.  
  132.     /* Get information on the startup volume SYNCHRONOUSLY, by passing pointer to our param block */
  133.     if (localError = PBHGetVInfo((HParmBlkPtr)&thePB,false))    // Error getting information
  134.         return( ret );
  135.     
  136.     wPtr = FrontWindow();                                    // Get frontmost window
  137.     if( wPtr )                                                // If one exists, check if the name = startup volume name
  138.     {
  139.         GetWTitle(wPtr, winTitle);                            // Get the name of the window
  140.         if(IUEqualString(winTitle, thePB.ioNamePtr) == 0)    // Does the window name equal the directory name
  141.             ret = true;
  142.     }
  143.  
  144.     return( ret );
  145. } // IsFrontWindowStartupVol();
  146.  
  147.  
  148. pascal Boolean     IsOpenWindowStartupVol()
  149. {
  150.     Boolean        ret    =    false;
  151.     short        startupVolRefNum;
  152.     long        systemDirID;
  153.     VolumeParam    thePB;
  154.     WindowPtr    wPtr;
  155.     OSErr        localError;
  156.     Str255        winTitle;
  157.     char        nameString[32];
  158.     
  159.     if( FindSysFolder( &startupVolRefNum, &systemDirID ))    // Error getting volume ref num of startup volume
  160.         return( ret );
  161.  
  162.     /* Set the param block up for getting information about the startup volume */
  163.     thePB.ioCompletion = nil;
  164.     thePB.ioVolIndex = 0;                                    // Use ioVRefNum field only
  165.     thePB.ioVRefNum = startupVolRefNum;                        // Use the startup volume reference for lookup
  166.     thePB.ioNamePtr = nameString;
  167.  
  168.     /* Get information on the startup volume SYNCHRONOUSLY, by passing pointer to our param block */
  169.     if (localError = PBHGetVInfo((HParmBlkPtr)&thePB,false))    // Error getting information
  170.         return( ret );
  171.  
  172.     wPtr = FrontWindow();                                    // Get frontmost window
  173.     while( wPtr )                                            // For all windows, check if name = startup volume name
  174.     {
  175.         GetWTitle(wPtr, winTitle);                            // Get the name of the window
  176.         if(IUEqualString(winTitle, thePB.ioNamePtr) == 0)    // Does the window name equal the directory name
  177.             return( true );
  178.         wPtr = (WindowPtr)((WindowPeek)wPtr)->nextWindow;    // Go on to next window
  179.     }
  180.     
  181.     return( ret );
  182. } // IsOpenWindowStartupVol();
  183.  
  184.  
  185. pascal Boolean     IsCDOnStartupVol()
  186. {
  187.     Boolean        ret    =    false;
  188.     short        startupVolRefNum;
  189.     long        systemDirID;
  190.     short        currentVol;
  191.  
  192.     if( FindSysFolder( &startupVolRefNum, &systemDirID ))        // Error getting volume ref num of startup volume
  193.         return( ret );
  194.         
  195.     currentVol = GetSFCurVol();
  196.     
  197.     return(currentVol == startupVolRefNum);
  198. } // IsCDOnStartupVol();
  199.  
  200.  
  201. pascal Boolean     IsPrintMonitorInstalled()
  202. {
  203.     Boolean        ret    =    false;
  204.     short        startupVolRefNum;
  205.     long        extensionsDirID;
  206.  
  207.     if( FindExtFolder( &startupVolRefNum, &extensionsDirID ))    // Error getting volume ref num or extensions directory ID
  208.         return( ret );
  209.         
  210.     if( FindFile( "\pPrintMonitor", startupVolRefNum, extensionsDirID ))    // Error finding the file
  211.         return( ret );
  212.  
  213.     return( true );                                                // File was found OK
  214. } // IsPrintMonitorInstalled();
  215.  
  216.  
  217. pascal Boolean     IsAppleShareInstalled()
  218. {
  219.     Boolean        ret    =    false;
  220.     short        startupVolRefNum;
  221.     long        extensionsDirID;
  222.  
  223.     if( FindExtFolder( &startupVolRefNum, &extensionsDirID ))    // Error getting volume ref num or extensions directory ID
  224.         return( ret );
  225.         
  226.     if( FindFile( "\pAppleShare", startupVolRefNum, extensionsDirID ))        // Error finding the file
  227.         return( ret );
  228.  
  229.     return( true );                                                // File was found OK
  230. } // IsAppleShareInstalled();
  231.  
  232.  
  233. pascal Boolean     IsEtherTalkInstalled()
  234. {
  235.     Boolean        ret    =    false;
  236.     short        startupVolRefNum;
  237.     long        extensionsDirID;
  238.  
  239.     if( FindExtFolder( &startupVolRefNum, &extensionsDirID ))    // Error getting volume ref num or extensions directory ID
  240.         return( ret );
  241.         
  242.     if( FindFile( "\pNetwork Extension", startupVolRefNum, extensionsDirID ))    // Error finding the file
  243.         return( ret );
  244.  
  245.     if( FindFile( "\pEtherTalk Phase 2", startupVolRefNum, extensionsDirID ))    // Error finding the file
  246.         return( ret );
  247.  
  248.     return( true );                                                // File was found OK
  249. } // IsEtherTalkInstalled();
  250.  
  251.  
  252. pascal Boolean     IsTokenTalkInstalled()
  253. {
  254.     Boolean        ret    =    false;
  255.     short        startupVolRefNum;
  256.     long        extensionsDirID;
  257.  
  258.     if( FindExtFolder( &startupVolRefNum, &extensionsDirID ))    // Error getting volume ref num or extensions directory ID
  259.         return( ret );
  260.         
  261.     if( FindFile( "\pNetwork Extension", startupVolRefNum, extensionsDirID ))    // Error finding the file
  262.         return( ret );
  263.  
  264.     if( FindFile( "\pTokenTalk", startupVolRefNum, extensionsDirID ))            // Error finding the file
  265.         return( ret );
  266.  
  267.     if( FindFile( "\pA/ROSE", startupVolRefNum, extensionsDirID ))        // Error finding the file
  268.         return( ret );
  269.  
  270.     return( true );                                                // File was found OK
  271. } // IsEtherTalkInstalled();
  272.  
  273.  
  274. pascal Boolean    IsCPInstalled(FileStatePtr fileMsg)
  275. {
  276.     Boolean        ret    =    false;
  277.     short        startupVolRefNum;
  278.     long        controlPanelsDirID;
  279.  
  280.     startupVolRefNum = 0;
  281.     controlPanelsDirID = 0;
  282.  
  283.     if( FindFolder( kOnSystemDisk, kControlPanelFolderType, kDontCreateFolder, &startupVolRefNum, &controlPanelsDirID ))
  284.         return( ret );
  285.         
  286.     if( FindFile( fileMsg->fileName.str, startupVolRefNum, controlPanelsDirID ))    // Error finding the file
  287.         return( ret );
  288.  
  289.     return( true );                                                // File was found OK
  290. } // IsCPInstalled();
  291.  
  292.  
  293. pascal Boolean    IsFileInstalled(FileStatePtr fileMsg)
  294. {
  295.     Boolean        ret    =    false;
  296.     short        startupVolRefNum;
  297.     long        theDirID;
  298.  
  299.     startupVolRefNum = 0;
  300.     theDirID = 0;
  301.  
  302.     if( FindFolder( kOnSystemDisk, fileMsg->sysFolderCode, kDontCreateFolder, &startupVolRefNum, &theDirID ))
  303.         return( ret );
  304.         
  305.     if( FindFile( fileMsg->fileName.str, startupVolRefNum, theDirID ))    // Error finding the file
  306.         return( ret );
  307.         
  308.     return( true );                                                // File was found OK
  309. } // IsCPInstalled();
  310.  
  311.  
  312. OSErr    FindSysFolder(short *foundVRefNum, long *foundDirID)
  313. {
  314.     OSErr            err;
  315.     
  316.     *foundVRefNum = 0;
  317.     *foundDirID = 0;
  318.     err = FindFolder( kOnSystemDisk, kSystemFolderType, kDontCreateFolder, foundVRefNum, foundDirID );
  319.     return( err );
  320. } // FindSysFolder();
  321.  
  322.  
  323. OSErr    FindExtFolder(short *foundVRefNum, long *foundDirID)
  324. {
  325.     OSErr            err;
  326.     
  327.     *foundVRefNum = 0;
  328.     *foundDirID = 0;
  329.     err = FindFolder( kOnSystemDisk, kExtensionFolderType, kDontCreateFolder, foundVRefNum, foundDirID );
  330.     return( err );
  331. } // FindExtFolder();
  332.  
  333.  
  334. OSErr    FindFile(char *filename, short theVolume, long theDirID)
  335. {
  336.     OSErr            err;
  337.     HFileInfo        thePB;
  338.     
  339.     /* Set the param block up for getting information about the given file */
  340.     thePB.ioCompletion = nil;
  341.     thePB.ioNamePtr = filename;                            // File name we want
  342.     thePB.ioVRefNum = theVolume;                        // Volume to be searched
  343.     thePB.ioFDirIndex = 0;                                // Use the filename to find our file
  344.     thePB.ioDirID = theDirID;                            // The directory to be searched
  345.  
  346.     if (err = PBGetCatInfo((CInfoPBPtr)&thePB,false))    // Error getting information
  347.         return( err );
  348.  
  349.     return( 0 );
  350. } // FindFile();
  351.  
  352.  
  353. short    GetSFCurVol()
  354. {
  355.     short        volRef;
  356.         
  357.     volRef = (short*)SFSaveDisk;
  358.     volRef = -volRef;
  359.     return( volRef );
  360. }
  361.